class ArticleController < ApplicationController
  before_filter :user_authorize,:except => [:show,:brife]
  before_filter :sys_before_log
  #before_filter :privilege_filter
  
  def show
    @article = Article.find(params[:id])
  end

  def articleList
    
  end

  def editArticle
    
  end

  def brife
    
  end

  def getArticles
    pageBegin =  params[:start]
    pageEnd =  params[:limit]
    total = Article.count
    articles = Article.find(:all,:offset => pageBegin.to_s,:limit =>pageEnd.to_s)
    jsonstr="{totalProperty:"+total.to_s+",root:"+articles.to_json(:include => {:auditor=>{:only=>:name}},:only=>[:id,:title,:sub_type])+"}"
    render :text=>jsonstr,:layout=>false
  end

  def edit
    article = Article.find(params[:id])
    render :text=>article.to_json(),:layout=>false
  end

  def update
    begin
      article = Article.find(params[:id])
      article.auditor_id = session[:auditor_id]
      article.content = params[:content]
      article.save!
      info = 'success'
    rescue Exception=>e
      info = e.to_s
    end
    result="{success:true,info:\"#{info}\"}"
    render :text=>result,:layout=>false
  end
end
